New LiquidCrystal library: /Users/fmalpartida/Documents/development/mercurial repos/SW/NewliquidCrystal/FastIO.h Source File

New LiquidCrystal library 1.3.2 Generic LCD control library

- Main Page
- Related Pages
- Classes
- Files

- File List

/Users/fmalpartida/Documents/development/mercurial repos/SW/NewliquidCrystal/FastIO.h
1 // ---------------------------------------------------------------------------
2 // Created by Florian Fida on 20/01/12
3 // Copyright 2012 - Under creative commons license 3.0:
4 // Attribution-ShareAlike CC BY-SA
5 // http://creativecommons.org/licenses/by-sa/3.0/
6 //
7 // This software is furnished "as is", without technical support, and with no
8 // warranty, express or implied, as to its usefulness for any purpose.
9 // ---------------------------------------------------------------------------
10 // fio_shiftOut1 functions are based on Shif1 protocol developed by Roman Black
11 // (http://www.romanblack.com/shift1.htm)
12 //
13 // Thread Safe: No
14 // Extendable: Yes
15 //
16 // @file FastIO.h
17 // This file implements basic fast IO routines.
18 //
19 // @brief
20 //
21 // @version API 1.0.0
22 //
23 // @author Florian Fida -
24 // 2012-03-16 bperrybap mods for chipkit32 (pic32) Arduino
25 // support chipkit:
26 // (https://github.com/chipKIT32/chipKIT32-MAX/blob/master/hardware/pic32/
27 // cores/pic32/wiring_digital.c)
28 // ---------------------------------------------------------------------------
29 #ifndef _FAST_IO_H_
30 #define _FAST_IO_H_
31
32 #if (ARDUINO < 100)
33 #include <WProgram.h>
34 #else
35 #include <Arduino.h>
36 #endif
37
38 #include <pins_arduino.h> // pleasing sanguino core
39 #include <inttypes.h>
40
41
42 #define SKIP 0x23
43
44 #if defined (__AVR__)
45 #include <util/atomic.h> // for critical section management
46 typedef uint8_t fio_bit;
47 typedef volatile uint8_t *fio_register;
48
49
50 #elif defined(__PIC32MX__)
51 typedef uint32_t fio_bit;
52 typedef volatile uint32_t *fio_register;
53
54
55 #else
56 // fallback to Arduino standard digital i/o routines
57 #define FIO_FALLBACK
58 #define ATOMIC_BLOCK(dummy) if(true)
59 #define ATOMIC_RESTORESTATE
60 typedef uint8_t fio_bit;
61 typedef uint8_t fio_register;
62 #endif
63
64
65
66 #if !defined(FIO_FALLBACK) && !defined(ATOMIC_BLOCK)
67 /*
68 * Define an ATOMIC_BLOCK that implements ATOMIC_FORCEON type
69 * Using the portable Arduino interrupts() and noInterrupts()
70 */
71 #define ATOMIC_RESTORESTATE ATOMIC_FORCEON // sorry, no support for save/restore yet.
72 #define ATOMIC_FORCEON uint8_t sreg_save \
73 __attribute__((__cleanup__(__iSeiParam))) = 0
74
75 static __inline__ uint8_t __iCliRetVal(void)
76 {
77 noInterrupts();
78 return(1);
79 }
80 static __inline__ void __iSeiParam(const uint8_t *__s)
81 {
82 interrupts();
83 }
84 #define ATOMIC_BLOCK(type) for(type, __Todo = __iCliRetVal(); __Todo; __Todo = 0)
85
86 #endif // end of block to create compatible ATOMIC_BLOCK()
87
88
89
97 fio_register fio_pinToOutputRegister(uint8_t pin, uint8_t initial_state = LOW);
98
106 fio_register fio_pinToInputRegister(uint8_t pin);
107
115 fio_bit fio_pinToBit(uint8_t pin);
116
117
127 // __attribute__ ((always_inline)) /* let the optimizer decide that for now */
128 void fio_digitalWrite ( fio_register pinRegister, fio_bit pinBit, uint8_t value );
129
136 #ifndef FIO_FALLBACK
137 #define fio_digitalWrite_LOW(reg,bit) *reg &= ~bit
138 #define fio_digitalWrite_HIGH(reg,bit) *reg |= bit
139 #define fio_digitalWrite_SWITCH(reg,bit) *reg ^= bit
140 #define fio_digitalWrite_SWITCHTO(reg,bit,val) fio_digitalWrite_SWITCH(reg,bit)
141 #else
142 // reg -> dummy NULL, bit -> pin
143 #define fio_digitalWrite_HIGH(reg,bit) digitalWrite(bit,HIGH)
144 #define fio_digitalWrite_LOW(reg,bit) digitalWrite(bit,LOW)
145 #define fio_digitalWrite_SWITCH(reg,bit) digitalWrite(bit, !digitalRead(bit))
146 #define fio_digitalWrite_SWITCHTO(reg,bit,val) digitalWrite(bit,val);
147 #endif
148
158 int fio_digitalRead ( fio_register pinRegister, fio_bit pinBit );
159
171 void fio_shiftOut( fio_register dataRegister, fio_bit dataBit, fio_register clockRegister,
172 fio_bit clockBit, uint8_t value, uint8_t bitOrder );
173
184 void fio_shiftOut(fio_register dataRegister, fio_bit dataBit, fio_register clockRegister, fio_bit clockBit);
185
194 void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch = false);
202 void fio_shiftOut1(uint8_t pin, uint8_t value, boolean noLatch = false);
210 void fio_shiftOut1_init(fio_register shift1Register, fio_bit shift1Bit);
217 void fio_shiftOut1_init(uint8_t pin);
218
219 #endif // FAST_IO_H